<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" style="margin-top: 20px" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <a-form-item label="委外订单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.orderCode"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item label="坯布编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.greyCode"
                @press-enter="huiche"
              />
            </a-form-item>
          </a-form>
        </div>
        <div class="my-tool-bar">
          <Toolbar
            style="float: right"
            :items="toolbarList"
            @select="selectHandler"
            @audit="auditDate"
            @rejected="rejectData"
            @flycloth="printOk"
          ></Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs :lazy-load="true" :justify="true" default-active-key="1" @change="handoff">
        <a-tab-pane title="待处理" key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :localeText="localeText1"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableList"
            :columnDefs="tc"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="pageData.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="pageData.size"
            :current="pageData.page"
          />
        </a-tab-pane>
        <a-tab-pane title="待审核" key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            @grid-ready="gridReady1"
            style="height: calc(100% - 45px)"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            :localeText="localeText1"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableList1"
            :columnDefs="tc1"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="pageData.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="pageData.size"
            :current="pageData.page"
          />
        </a-tab-pane>
        <a-tab-pane title="已审核" key="3">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            @grid-ready="gridReady2"
            style="height: calc(100% - 45px)"
            @columnResized="onColumnResized3"
            @columnMoved="onColumnMoved3"
            @columnVisible="onColumnVisible3"
            :localeText="localeText1"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableList2"
            :columnDefs="tc2"
          >
          </AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="pageData.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="pageData.size"
            :current="pageData.page"
          />
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      height="90%"
      placement="bottom"
      :ok-loading="pageData.pageLoading"
      :visible="pageData.showAdd"
      unmount-on-close
      :mask-closable="false"
      @ok="sideOk"
      @cancel="sideNo"
    >
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div style="min-width: 1500px; overflow: auto" class="scrollbar">
        <el-scrollbar>
          <a-collapse :default-active-key="[1, 2, 3]">
            <a-collapse-item header="基本信息" :key="1">
              <AgGridVuesCopys
                :rowHeight="33"
                :headerHeight="33"
                :suppressCopyRowsToClipboard="true"
                rowSelection="multiple"
                @grid-ready="gridReady3"
                style="height: 120px"
                :localeText="localeText1"
                :defaultColDef="defaultColDef"
                class="ag-theme-alpine"
                :rowData="tableList1"
                :columnDefs="tc3"
              >
              </AgGridVuesCopys>
            </a-collapse-item>

            <!-- 工艺信息 -->
            <a-collapse-item header="工艺信息" :key="2">
              <AgGridVuesCopys
                :rowHeight="33"
                :headerHeight="33"
                :suppressCopyRowsToClipboard="true"
                rowSelection="multiple"
                @grid-ready="gridReady4"
                style="height: 120px"
                :localeText="localeText1"
                :defaultColDef="defaultColDef"
                class="ag-theme-alpine"
                :rowData="tableList1"
                :columnDefs="tc4"
              >
              </AgGridVuesCopys>
            </a-collapse-item>
            <a-collapse-item header="报价信息" :key="3">
              <a-form
                style="padding-left: 40px"
                size="mini"
                ref="formRef"
                layout="inline"
                :model="dataForm"
              >
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="委外订单号">
                  <a-input class="bacClass" v-model="dataForm.orderCode" disabled></a-input>
                </a-form-item>
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="匹数">
                  <a-input class="bacClass" v-model="dataForm.totalNum" disabled></a-input>
                </a-form-item>
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="订单重量">
                  <a-input class="bacClass" v-model="dataForm.totalWeight" disabled></a-input>
                </a-form-item>
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="单位">
                  <a-input class="bacClass" v-model="dataForm.unit" disabled></a-input>
                </a-form-item>
                <a-form-item
                  :style="{ width: '400px' }"
                  label-col-flex="150px"
                  label="代工厂商"
                  field="producer"
                  :rules="[{ required: true, message: '代工厂商必填' }]"
                >
                  <a-input
                    class="bacClass"
                    v-model="dataForm.producer"
                    :disabled="!pageData.isEdit"
                  ></a-input>
                </a-form-item>
                <a-form-item
                  label-col-flex="150px"
                  label="交期"
                  field="deliveryDate"
                  :rules="[{ required: true, message: '交期必填' }]"
                >
                  <a-date-picker
                    popup-container="html"
                    class="bacClass"
                    :style="{ width: '338px' }"
                    v-model="dataForm.deliveryDate"
                    :disabled="!pageData.isEdit"
                    :disabledDate="disablePreviousDates"
                  />
                </a-form-item>
                <a-form-item label-col-flex="150px" label="付款方式" :style="{ width: '400px' }">
                  <a-select
                    popup-container="html"
                    class="bacClass"
                    :loading="loading"
                    @search="handleSearch"
                    v-model="dataForm.payment"
                    :disabled="!pageData.isEdit"
                    :filter-option="false"
                    allow-search
                    allow-clear
                    @focus="focusSel"
                  >
                    <a-option v-for="item in pageData.typeList" :value="item.settlementName"
                      >{{ item.settlementName }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '400px' }"
                  label-col-flex="150px"
                  label="报价单价"
                  field="price"
                  :rules="[{ required: true, message: '报价单价必填' }]"
                >
                  <a-input-number
                    class="bacClass"
                    v-model="dataForm.price"
                    @change="priceChange()"
                    :disabled="!pageData.isEdit"
                    :min="0"
                    :precision="4"
                  />
                </a-form-item>
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="报价总价">
                  <a-input class="bacClass" v-model="dataForm.totalPrice" disabled></a-input>
                </a-form-item>
                <a-form-item :style="{ width: '400px' }" label-col-flex="150px" label="报价图片">
                  <a-upload
                    list-type="picture"
                    :file-list="fileList"
                    :limit="1"
                    :auto-upload="false"
                    :show-upload="true"
                    @change="handleChange"
                    image-preview
                    :disabled="!pageData.isEdit"
                  >
                  </a-upload>
                </a-form-item>
              </a-form>
              <img style="padding-left: 40px" :src="quoteBase64" />
            </a-collapse-item>
            <a-collapse-item header="原纱出库信息" :key="4" v-if="key == 3">
              <a-table
                :columns="tc8"
                :data="tableList3"
                :span-method="dataSpanMethod1"
                :pagination="false"
                :bordered="{ cell: true }"
              >
              </a-table>
            </a-collapse-item>
          </a-collapse>
        </el-scrollbar>
      </div>
    </a-drawer>

    <!-- 布飞打印模板 -->
    <a-modal
      fullscreen
      v-model:visible="visible"
      :ok-loading="(dataForm.pageLoading = false)"
      @cancel="visible = false"
      ok-text="确认"
      cancelText="关闭"
      :footer="false"
    >
      <template #title>选择织布单号</template>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        rowSelection="multiple"
        @grid-ready="gridReady5"
        style="height: 110px; margin-top: 30px; margin-bottom: 50px"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="tableList1"
        :columnDefs="tc5"
        :localeText="localeText1"
      ></AgGridVuesCopys>
    </a-modal>
    <a-drawer
      ok-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      @ok="bfShowAdd = false"
      :width="'100%'"
      :height="'90%'"
      :visible="bfShowAdd"
      placement="bottom"
      :hide-cancel="true"
      @cancel="bfShowAdd = false"
    >
      <template #title> 模版 </template>
      <iframe v-if="bfShowAdd" style="width: 100%; height: 100%" :src="srcUrl"></iframe>
    </a-drawer>

    <!-- 原纱出库弹窗 -->
    <a-drawer
      ok-text="申请出库"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      @ok="yarnOk"
      @cancel="yarnShow = false"
      :width="'100%'"
      :height="'90%'"
      :visible="yarnShow"
      placement="bottom"
    >
      <template #title>原纱出库</template>
      <a-table
        :columns="tc6"
        :data="tableList3"
        :span-method="dataSpanMethod"
        :pagination="false"
        :bordered="{ cell: true }"
        v-model:selected-keys="selectedRowKeys"
      >
        <template #pieceNumber="{ record }">
          <a-input-number
            v-model="record.pieceNumber"
            class="bacClass"
            :min="0"
            :precision="0"
            @change="NumChange(record)"
            :disabled="record.outStockNumber"
          />
        </template>
        <template #bulkNumber="{ record }">
          <a-input-number
            v-model="record.bulkNumber"
            class="bacClass"
            :min="0"
            :precision="0"
            :disabled="record.outStockNumber"
          />
        </template>
        <template #bulkCount="{ record }">
          <a-input-number
            v-model="record.bulkCount"
            class="bacClass"
            :min="0"
            :precision="0"
            :disabled="record.outStockNumber"
          />
        </template>
        <template #act="{ record }">
          <a-button
            size="mini"
            type="primary"
            shape="round"
            @click="kcSeclect(record)"
            :disabled="record.outStockNumber"
            >库存</a-button
          >
        </template>
      </a-table>
    </a-drawer>
    <!-- <a-modal :drawer-style="{ 'zIndex': 9999 }" :mask-closable="false" width="80%" :visible="pageData.showAdd"
           unmountOnClose @ok="sideOk" @cancel="pageData.showAdd = false" cancel-text='关闭' ok-text='保存'> -->
    <a-modal v-model:visible="CKvisible" :width="1200" :mask-closable="false" :footer="false">
      <template #title> 选择库存 </template>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        @grid-ready="gridReady7"
        style="height: 500px"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="tableList4"
        :columnDefs="tc7"
        :localeText="localeText1"
      ></AgGridVuesCopys>
      <paginationCopys
        :total="pageData.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSize2"
        @page-size-change="change2"
        style="justify-content: center; margin-top: 10px"
        :page-size="pageData.size"
        :current="pageData.page"
      />
      <span slot="footer" style="float: right">
        <a-button style="margin-right: 10px" @click="handleNo">取消</a-button>
        <a-button type="primary" :loading="(Loading = false)" @click="handleOk">确认</a-button>
      </span>
    </a-modal>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { pagingList } from '@/api/paging'
  import { post, get } from '@/api/http'
  import {
    useTable,
    useRowKey,
    useTableColumn,
    usePagination,
    useRowSelection,
  } from '@/hooks/table'
  import emitter from '@/hooks/useEventBus'
  import { ref, reactive, onMounted, toRefs } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Form, Message, Modal } from '@arco-design/web-vue'
  import { FormInstance } from '@arco-design/web-vue/es/form'
  import { baseURL } from '../../../api/axios.config'
  import axios from 'axios'
  import filedownload from 'js-file-download'
  import PageTabelLayout from '@/components/pageTabelLayout.vue'
  import { AnyARecord } from 'dns'
  
  import { localeText } from '@/api/aggridZw'
  import OutboufeiListdy from './OutboufeiListdy.vue'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState03 } from '@/hooks/useGridState'
  const tableList = ref([])
  const tableList1 = ref([])
  const tableList2 = ref([])
  const tableList3 = ref([])
  const tableList4 = ref([])
  const headerShow = ref(true)
  const pagingList1: any = ref(pagingList)
  const localeText1: any = ref(localeText)
  const key = ref(1)
  const quoteBase64 = ref()
  const toolbarList: any = ref(['查询', '驳回'])

  const handoff = (e: any) => {
    key.value = e
    if (e == 1) {
      doRefresh()
      toolbarList.value = ['查询', '驳回']
    } else if (e == 2) {
      doRefresh1()
      toolbarList.value = ['查询', '审核', '驳回']
    } else if (e == 3) {
      doRefresh2()
      toolbarList.value = ['查询', '打印布飞']
    }
  }

  const pageData: any = reactive({
    total: 10,
    size: 10,
    page: 1,
    showAdd: false,
    sideTitle: '',
    pageLoading: false,
    orderCode: '',
    greyCode: '',
    isEdit: true,
    typeList: [],
  })

  const dataForm: any = reactive({
    orderCode: '',
    totalNum: null,
    totalWeight: null,
    unit: '',
    producer: '',
    price: null,
    totalPrice: null,
    deliveryDate: '',
    payment: '',
    quotationImg: null,
  })

  const PageSize = (val: any) => {
    pageData.page = val
    if (key.value == 1) {
      doRefresh()
    } else if (key.value == 2) {
      doRefresh1()
    } else if (key.value == 3) {
      doRefresh2()
    }
  }

  const change = (val: any) => {
    pageData.size = val
    if (key.value == 1) {
      doRefresh()
    } else if (key.value == 2) {
      doRefresh1()
    } else if (key.value == 3) {
      doRefresh2()
    }
  }

  const PageSize2 = (val: any) => {
    pageData.page = val
    kcSeclect(record)
  }
  const change2 = (val: any) => {
    pageData.size = val
    kcSeclect(record)
  }
  // 表格准备事件
  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }
  const gridOption1 = ref()
  const colState2 = ref()
  const gridReady1 = (params: any) => {
    gridOption1.value = params.api
    colState2.value = params.columnApi
  }
  const gridOption2 = ref()
  const colState3 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState3.value = params.columnApi
  }
  const gridOption3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
  }
  const gridOption4 = ref()
  const gridReady4 = (params: any) => {
    gridOption4.value = params.api
  }

  const gridOption5 = ref()
  const gridReady5 = (params: any) => {
    gridOption5.value = params.api
  }

  const gridOption7 = ref()
  const gridReady7 = (params: any) => {
    gridOption7.value = params.api
  }
  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'firmName',
      width: 150,
    },
    {
      headerName: '织布单号',
      field: 'planOrderCode',
      width: 150,
    },
    {
      headerName: '委外订单号',
      field: 'orderCode',
      width: 180,
    },
    {
      headerName: '坯布编号',
      field: 'greyCode',
      width: 180,
    },
    {
      headerName: '坯布名称',
      field: 'greyName',
      width: 180,
    },
    {
      headerName: '面料种类',
      field: 'fabricType',
      width: 180,
    },
    {
      headerName: '匹数',
      field: 'totalNum',
      width: 180,
    },
    {
      headerName: '订单重量',
      field: 'totalWeight',
      width: 180,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 180,
    },
    {
      headerName: '计划状态',
      field: 'planState',
      key: '委外',
      filter: false,
      width: 180,
      cellRenderer: {
        template: `<div>委外</div>`,
      },
    },
    {
      // 0 未审核，1 通过，2 否决
      headerName: '状态',
      field: 'status',
      filter: false,
      width: 180,
      cellRenderer: {
        template: `<el-tag type="warning">未审核</el-tag>`,
      },
    },
    {
      headerName: '编辑',
      field: 'action',
      width: 155,
      pinned: 'right',
      filter: false,
      cellRenderer: {
        template: `<a-space>
                         <a-tag class="tagCss" @click="b" v-if="e">报价录入</a-tag>
                         <a-tag class="tagCss" v-else disabled style="color:#d1d1d1 !important">报价录入</a-tag>
                         <a-tag class="tagCss" @click="c">详情</a-tag>
                      </a-space>`,
        setup(props: any) {
          const b = () => {
            quoteEntry(props.params.data)
          }
          const c = () => {
            Detail(props.params.data)
          }
          return {
            b,
            c,
            e: props.params.data.audited == 0,
          }
        },
      },
    },
  ]

  const tc1 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'firmName',
      width: 150,
    },
    {
      headerName: '织布单号',
      field: 'planOrderCode',
      width: 150,
    },
    {
      headerName: '委外订单号',
      field: 'orderCode',
      width: 150,
    },
    /*{
        headerName: '客户',
        field: 'customName',
        width: 150
    },*/
    {
      headerName: '坯布编号',
      field: 'greyCode',
      width: 150,
    },
    {
      headerName: '坯布名称',
      field: 'greyName',
      width: 150,
    },
    {
      headerName: '面料种类',
      field: 'fabricType',
      width: 150,
    },
    {
      headerName: '匹数',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '订单重量',
      field: 'totalWeight',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '计划状态',
      field: 'planState',
      key: '委外',
      filter: false,
      width: 150,
      cellRenderer: {
        template: `<div>委外</div>`,
      },
    },
    {
      headerName: '代工厂商',
      field: 'producer',
      width: 150,
    },
    {
      headerName: '报价单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '报价总价',
      field: 'totalPrice',
      width: 150,
    },
    {
      headerName: '付款方式',
      field: 'payment',
      width: 150,
    },
    {
      headerName: '交货期限',
      field: 'deliveryDate',
      width: 150,
    },
    {
      headerName: '状态',
      field: 'status',
      width: 150,
      filter: false,
      cellRenderer: {
        template: `<el-tag type="warning">未审核</el-tag>`,
      },
    },
    {
      headerName: '编辑',
      field: 'action',
      width: 150,
      pinned: 'right',
      filter: false,
      cellRenderer: {
        template: `<a-space>
                         <a-tag class="tagCss" @click="c">详情</a-tag>
                      </a-space>`,
        setup(props: any) {
          const c = () => {
            Detail(props.params.data)
          }
          return {
            c,
          }
        },
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'outSouringCompany',
      width: 150,
    },
    {
      headerName: '织布单号',
      field: 'planOrderCode',
      width: 150,
    },
    {
      headerName: '委外订单号',
      field: 'orderCode',
      width: 150,
    },
    {
      headerName: '坯布编号',
      field: 'greyCode',
      width: 150,
    },
    {
      headerName: '坯布名称',
      field: 'greyName',
      width: 150,
    },
    {
      headerName: '面料种类',
      field: 'fabricType',
      width: 150,
    },
    {
      headerName: '匹数',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '订单重量',
      field: 'totalWeight',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '计划状态',
      field: 'planState',
      key: '委外',
      filter: false,
      width: 150,
      cellRenderer: {
        template: `<div>委外</div>`,
      },
    },
    {
      headerName: '代工厂商',
      field: 'producer',
      width: 150,
    },
    {
      headerName: '报价单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '报价总价',
      field: 'totalPrice',
      width: 150,
    },
    {
      headerName: '付款方式',
      field: 'payment',
      width: 150,
    },
    {
      headerName: '交货期限',
      field: 'deliveryDate',
      width: 150,
    },
    {
      headerName: '状态',
      field: 'adtStatus',
      width: 150,
      cellRenderer: {
        template: `<el-tag v-if="e == 1" type="success">已审核</el-tag>
            <el-tag v-if="e == 2">已驳回</el-tag>`,
        setup(props: any) {
          return {
            e: props.params.data.adtStatus,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1' ? '已审核' : params.value == '2' ? '已驳回' : ''
        },
      },
    },
    {
      headerName: '编辑',
      field: 'action',
      width: 150,
      filter: false,
      pinned: 'right',
      cellRenderer: {
        template: `<a-space>
                         <a-tag class="tagCss" @click="a">原纱出库</a-tag>
                         <a-tag class="tagCss" @click="b">详情</a-tag>
                      </a-space>`,
        setup(props: any) {
          const a = () => {
            yarnOut(props.params.data)
          }
          const b = () => {
            Detail(props.params.data)
          }
          return {
            a,
            b,
          }
        },
      },
    },
  ]

  const tc3 = [
    {
      headerName: '坯布编号',
      field: 'greyCode',
      width: 150,
    },
    {
      headerName: '是否本集团',
      field: 'processType',
      width: 150,
      cellRenderer: {
        template: `<div>{{ states==0 ? '本集团':'外加工' }}</div>`,
        setup(props: any) {
          return {
            states: props.params.data.processType,
          }
        },
      },
    },
    {
      headerName: '坯布功能位代号',
      field: 'feature',
      width: 150,
    },
    {
      headerName: '纱线类别',
      field: 'yarnCountCategory',
      width: 150,
    },
    {
      headerName: '坯布名称',
      field: 'grayFabricName',
      width: 150,
    },
    {
      headerName: '布类',
      field: 'mercery',
      width: 150,
    },
    {
      headerName: '英文名称',
      field: 'englishName',
      width: 150,
    },
    {
      headerName: '开发编号',
      field: 'exploitCode',
      width: 150,
    },
    {
      headerName: '备案编号',
      field: 'putOnRecordsCode',
      width: 150,
    },
    {
      headerName: '是否抽针',
      field: 'drawnNeedleState',
      width: 150,
      cellRenderer: {
        template: `<div>{{ states==0 ? '是':'否' }}</div>`,
        setup(props: any) {
          return {
            states: props.params.data.drawnNeedleState,
          }
        },
      },
    },
    {
      headerName: '是否开幅',
      field: 'scutchingState',
      width: 150,
      cellRenderer: {
        template: `<div>{{ states==0 ? '是':'否' }}</div>`,
        setup(props: any) {
          return {
            states: props.params.data.scutchingState,
          }
        },
      },
    },
    {
      headerName: '成分',
      field: 'ingredient',
      width: 150,
    },
    {
      headerName: '加工单价',
      field: 'machineUnit',
      width: 150,
    },
    {
      headerName: '英文成分',
      field: 'englishIngredient',
      width: 150,
    },
    {
      headerName: '产品日期',
      field: 'productTime',
      width: 150,
    },
    {
      headerName: '面料种类',
      field: 'fabricType',
      width: 150,
    },
    {
      headerName: '坯布组织',
      field: 'organization',
      width: 150,
    },
    {
      headerName: '成品门幅',
      field: 'finishedLimit',
      width: 150,
    },
    {
      headerName: '成品克重',
      field: 'finishedWeight',
      width: 150,
    },
  ]

  const tc4 = [
    {
      headerName: '机型',
      field: 'machineType',
      width: 150,
    },
    {
      headerName: '实际产量',
      field: 'activeOutput',
      width: 150,
    },
    {
      headerName: '理论产量',
      field: 'theoreticalYield',
      width: 150,
    },
    {
      headerName: '理论单价',
      field: 'theoryPrice',
      width: 150,
    },
    {
      headerName: '寸数',
      field: 'dimensionFigure',
      width: 150,
    },
    {
      headerName: '针数',
      field: 'needleCount',
      width: 150,
    },
    {
      headerName: '总针数',
      field: 'sumNeedleCount',
      width: 150,
    },
    {
      headerName: '总路数',
      field: 'alwaysGoes',
      width: 150,
    },
    {
      headerName: '颜色属性',
      field: 'colorAttribute',
      width: 150,
    },
    {
      headerName: '织机转数',
      field: 'loomRevolution',
      width: 150,
    },
    {
      headerName: '循环间距',
      field: 'circulationGap',
      width: 150,
    },
    {
      headerName: '胶管名称',
      field: 'sebificDuctName',
      width: 150,
    },
    {
      headerName: '织造备注',
      field: 'weavingNote',
      width: 150,
    },
  ]

  const tc5 = [
    {
      headerName: '织布单号',
      field: 'planOrderCode',
      width: 418,
    },
    {
      headerName: '坯布编号',
      field: 'greyCode',
      width: 418,
    },
    {
      headerName: '坯布名称',
      field: 'greyName',
      width: 418,
    },
    {
      headerName: '下单重量',
      field: 'orderWeight',
      width: 419,
    },
    {
      headerName: '编辑',
      field: 'action',
      width: 205,
      pinned: 'right',
      cellRenderer: {
        template: `<a-button @click="a" type="primary">打印</a-button>`,
        setup(props: any) {
          const a = () => {
            dyBoufeixs(props.params.data)
          }
          return {
            a,
          }
        },
      },
    },
  ]

  const tc6: any = [
    {
      title: '织布单号',
      dataIndex: 'planOrderCode',
      key: 'planOrderCode',
      width: 150,
    },
    {
      title: '坯布编号',
      dataIndex: 'greyCode',
      key: 'greyCode',
      width: 150,
    },
    {
      title: '坯布名称',
      dataIndex: 'greyName',
      key: 'greyName',
      width: 150,
    },
    {
      title: '仓库名称',
      dataIndex: 'warehouseName',
      key: 'warehouseName',
      width: 150,
    },
    {
      title: '供应商名称',
      dataIndex: 'supplierName',
      key: 'supplierName',
      width: 150,
    },
    {
      title: '用纱代码',
      dataIndex: 'yarnSource',
      key: 'yarnSource',
      width: 150,
    },
    {
      title: '纱长',
      dataIndex: 'yarnLength',
      key: 'yarnLength',
      width: 150,
    },
    {
      title: '纱线单位',
      dataIndex: 'yarnUnit',
      key: 'yarnUnit',
      width: 150,
    },
    {
      title: '原料编号',
      dataIndex: 'rawmaterialCode',
      key: 'rawmaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      dataIndex: 'rawmaterialName',
      key: 'rawmaterialName',
      width: 150,
    },
    {
      title: '色号',
      dataIndex: 'colorCode',
      key: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      dataIndex: 'colorName',
      key: 'colorName',
      width: 150,
    },
    {
      title: '等级',
      dataIndex: 'level',
      key: 'level',
      width: 150,
    },
    {
      title: '纱牌',
      dataIndex: 'yarnCard',
      key: 'yarnCard',
      width: 150,
    },
    {
      title: '纱批',
      dataIndex: 'batch',
      key: 'batch',
      width: 150,
    },
    {
      title: '用纱比例',
      dataIndex: 'yarnProportion',
      key: 'yarnProportion',
      width: 150,
    },
    {
      title: '织造损耗',
      dataIndex: 'weaveLoss',
      key: 'weaveLoss',
      width: 150,
    },
    {
      title: '纱损',
      dataIndex: 'yarnLoss',
      key: 'yarnLoss',
      width: 150,
    },
    {
      title: '配纱数量',
      dataIndex: 'withYarnNum',
      key: 'withYarnNum',
      fixed: 'right',
      width: 100,
    },
    {
      title: '单位',
      dataIndex: 'unit',
      key: 'unit',
      width: 150,
    },
    {
      title: '整件/件数',
      dataIndex: 'pieceNumber',
      key: 'pieceNumber',
      slotName: 'pieceNumber',
      fixed: 'right',
      width: 100,
    },
    {
      title: '整件件重',
      dataIndex: 'pieceWeight',
      key: 'pieceWeight',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/件数',
      dataIndex: 'bulkNumber',
      key: 'bulkNumber',
      slotName: 'bulkNumber',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/散重',
      dataIndex: 'bulkWeight',
      key: 'bulkWeight',
      fixed: 'right',
      width: 100,
    },
    {
      title: '总重量',
      dataIndex: 'weightTotal',
      key: 'weightTotal',
      fixed: 'right',
      width: 100,
    },
    {
      title: '整件/个数',
      dataIndex: 'pieceCount',
      key: 'pieceCount',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/个数',
      dataIndex: 'bulkCount',
      key: 'bulkCount',
      slotName: 'bulkCount',
      fixed: 'right',
      width: 100,
    },
    {
      title: '出库单号',
      dataIndex: 'outStockNumber',
      key: 'outStockNumber',
      fixed: 'right',
      width: 100,
    },
    {
      title: '编辑',
      dataIndex: 'act',
      key: 'act',
      slotName: 'act',
      fixed: 'right',
      width: 100,
    },
  ]

  const tc8: any = [
    {
      title: '织布单号',
      dataIndex: 'planOrderCode',
      key: 'planOrderCode',
      width: 150,
    },
    {
      title: '坯布编号',
      dataIndex: 'greyCode',
      key: 'greyCode',
      width: 150,
    },
    {
      title: '坯布名称',
      dataIndex: 'greyName',
      key: 'greyName',
      width: 150,
    },
    {
      title: '仓库名称',
      dataIndex: 'warehouseName',
      key: 'warehouseName',
      width: 150,
    },
    {
      title: '供应商名称',
      dataIndex: 'supplierName',
      key: 'supplierName',
      width: 150,
    },
    {
      title: '用纱代码',
      dataIndex: 'yarnSource',
      key: 'yarnSource',
      width: 150,
    },
    {
      title: '纱长',
      dataIndex: 'yarnLength',
      key: 'yarnLength',
      width: 150,
    },
    {
      title: '纱线单位',
      dataIndex: 'yarnUnit',
      key: 'yarnUnit',
      width: 150,
    },
    {
      title: '原料编号',
      dataIndex: 'rawmaterialCode',
      key: 'rawmaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      dataIndex: 'rawmaterialName',
      key: 'rawmaterialName',
      width: 150,
    },
    {
      title: '色号',
      dataIndex: 'colorCode',
      key: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      dataIndex: 'colorName',
      key: 'colorName',
      width: 150,
    },
    {
      title: '等级',
      dataIndex: 'level',
      key: 'level',
      width: 150,
    },
    {
      title: '纱牌',
      dataIndex: 'yarnCard',
      key: 'yarnCard',
      width: 150,
    },
    {
      title: '纱批',
      dataIndex: 'batch',
      key: 'batch',
      width: 150,
    },
    {
      title: '用纱比例',
      dataIndex: 'yarnProportion',
      key: 'yarnProportion',
      width: 150,
    },
    {
      title: '织造损耗',
      dataIndex: 'weaveLoss',
      key: 'weaveLoss',
      width: 150,
    },
    {
      title: '纱损',
      dataIndex: 'yarnLoss',
      key: 'yarnLoss',
      width: 150,
    },
    {
      title: '配纱数量',
      dataIndex: 'withYarnNum',
      key: 'withYarnNum',
      fixed: 'right',
      width: 100,
    },
    {
      title: '单位',
      dataIndex: 'unit',
      key: 'unit',
      width: 150,
    },
    {
      title: '整件/件数',
      dataIndex: 'pieceNumber',
      key: 'pieceNumber',
      slotName: 'pieceNumber',
      fixed: 'right',
      width: 100,
    },
    {
      title: '整件件重',
      dataIndex: 'pieceWeight',
      key: 'pieceWeight',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/件数',
      dataIndex: 'bulkNumber',
      key: 'bulkNumber',
      slotName: 'bulkNumber',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/散重',
      dataIndex: 'bulkWeight',
      key: 'bulkWeight',
      fixed: 'right',
      width: 100,
    },
    {
      title: '总重量',
      dataIndex: 'weightTotal',
      key: 'weightTotal',
      fixed: 'right',
      width: 100,
    },
    {
      title: '整件/个数',
      dataIndex: 'pieceCount',
      key: 'pieceCount',
      fixed: 'right',
      width: 100,
    },
    {
      title: '散件/个数',
      dataIndex: 'bulkCount',
      key: 'bulkCount',
      slotName: 'bulkCount',
      fixed: 'right',
      width: 100,
    },
    {
      title: '出库单号',
      dataIndex: 'outStockNumber',
      key: 'outStockNumber',
      fixed: 'right',
      width: 100,
    },
  ]

  const tc7: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '公司',
      field: 'firm',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouse',
      width: 150,
    },
    {
      headerName: '供应商名称',
      field: 'supplier',
      width: 150,
    },
    {
      headerName: '客户名称',
      field: 'customName',
      width: 150,
    },
    {
      headerName: '原料编号',
      field: 'yarnCode',
      width: 150,
    },
    {
      headerName: '原料名称',
      field: 'yarnName',
      width: 150,
    },
    {
      headerName: '纱牌',
      field: 'yarnBrand',
      width: 150,
    },
    {
      headerName: '纱批',
      field: 'productionBatch',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'level',
      width: 150,
    },
    {
      headerName: '可配色称',
      field: 'matchColor',
      width: 150,
    },
    {
      headerName: '色号',
      field: 'colorCode',
      width: 150,
    },
    {
      headerName: '色称',
      field: 'colorName',
      width: 150,
    },
    {
      headerName: '整件/件数',
      field: 'pieceNumber',
      width: 150,
    },
    {
      headerName: '整件/件重',
      field: 'pieceWeight',
      width: 150,
    },
    {
      headerName: '散件/件数',
      field: 'bulkNumber',
      width: 150,
    },
    {
      headerName: '散件/散重',
      field: 'bulkWeight',
      width: 150,
    },
    {
      headerName: '总重量',
      field: 'weightTotal',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '库位',
      field: 'location',
      width: 150,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 150,
    },
  ]
  //待处理 查询
  function doRefresh() {
    pageData.pageLoading = true
    updateGridState01()
    post({
      url: '/planSingle/oemOrder/findPagedOemOrders',
      data: {
        current: pageData.page,
        size: pageData.size,
        orderCode: pageData.orderCode,
        greyCode: pageData.greyCode,
        audited: 0,
        auditStatus: [0],
      },
    })
      .then(({ data, code }: any) => {
        if (code === 200) {
          //隐藏 已审核的数据
          for (var i = 0; i < data.records.length; i++) {
            if (data.records[i].audited != 0) {
              data.records.splice(i, 1)
            }
          }
          pageData.total = data.total
          gridOption.value.setRowData(data.records)
        }
      })
      .catch(console.log)
      .finally(() => {
        pageData.pageLoading = false
      })
  }

  //待审核 查询
  function doRefresh1() {
    pageData.pageLoading = true
    updateGridState02()
    post({
      url: '/planSingle/oemOrder/findQuotationsByCondition',
      data: {
        current: pageData.page,
        size: pageData.size,
        orderCode: pageData.orderCode,
        greyCode: pageData.greyCode,
        auditStatus: [0],
      },
    })
      .then(({ data, code }: any) => {
        if (code === 200) {
          pageData.total = data.total
          gridOption1.value.setRowData(data.records)
        }
      })
      .catch(console.log)
      .finally(() => {
        pageData.pageLoading = false
      })
  }

  //已审核 查询
  function doRefresh2() {
    pageData.pageLoading = true
    updateGridState03()
    post({
      url: '/planSingle/oemOrder/findQuotationsByCondition',
      data: {
        current: pageData.page,
        size: pageData.size,
        orderCode: pageData.orderCode,
        greyCode: pageData.greyCode,
        auditStatus: [1, 2],
      },
    })
      .then(({ data, code }: any) => {
        if (code === 200) {
          pageData.total = data.total
          gridOption2.value.setRowData(data.records)
        }
      })
      .catch(console.log)
      .finally(() => {
        pageData.pageLoading = false
      })
  }

  const selectHandler = () => {
    pageData.page = 1
    if (key.value == 1) {
      doRefresh()
    } else if (key.value == 2) {
      doRefresh1()
    } else if (key.value == 3) {
      doRefresh2()
    }
  }

  const huiche = () => {
    selectHandler()
  }

  //详情
  const Detail = (record: any) => {
    //循环对象 赋值
    for (let key in record) {
      dataForm[key] = record[key]
    }
    InQuery(record)
    // getFirmGroup()
    priceChange()
    LastData(record)
    if (key.value == 3) {
      ckSelect(record)
    }
    pageData.sideTitle = '详情'
    pageData.isEdit = false
    pageData.showAdd = true
  }

  //查询 基本信息 工艺信息
  const InQuery = (record: any) => {
    post({
      url: '/planSingle/oemOrder/getGreyInfo',
      data: { greyCode: record.greyCode },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gridOption3.value.setRowData(data)
        gridOption4.value.setRowData(data)
      }
    })
  }

  //根据账号回显报价工厂
  const getFirmGroup = () => {
    get({
      url: '/admin/acl/user/getMemberIdByJwtToken',
    }).then((res: any) => {
      post({
        url: 'admin/acl/user/findUserToken',
        data: { name: res },
      }).then((res: any) => {
        if (res.code === 200) {
          dataForm.producer = res.data.data.firmName
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          })
        }
      })
    })
  }

  //报价总价=报价单价 * 订单重量
  const priceChange = () => {
    dataForm.totalPrice = null
    dataForm.totalPrice = dataForm.price * dataForm.totalWeight
  }

  //获取前一次报价信息
  const LastData = (record: any) => {
    if (key.value == 1) {
      post({
        url: '/planSingle/orderQuotation/getQuotationByOrderId',
        data: { orderId: record.id },
      }).then((res: any) => {
        if (res.code == 200) {
          if (res.data != null) {
            quoteBase64.value = res.data.quotationImg
            dataForm.price = res.data.price
            dataForm.totalPrice = res.data.totalPrice
            dataForm.deliveryDate = res.data.deliveryDate
            dataForm.producer = res.data.producer
            dataForm.payment = res.data.payment
          }
        }
      })
    } else {
      post({
        url: '/planSingle/orderQuotation/getQuotationByOrderId',
        data: { orderId: record.orderId },
      }).then((res: any) => {
        if (res.code == 200) {
          if (res.data != null) {
            quoteBase64.value = res.data.quotationImg
            dataForm.price = res.data.price
            dataForm.totalPrice = res.data.totalPrice
            dataForm.deliveryDate = res.data.deliveryDate
            dataForm.producer = res.data.producer
          }
        }
      })
    }
  }

  //报价录入
  const quoteEntry = (record: any) => {
    pageData.pageLoading = true
    for (let key in record) {
      dataForm[key] = record[key]
    }
    dataForm.quotationImg = record.quotationImg
    dataForm.payment = ''
    InQuery(record)
    //报价信息
    // getFirmGroup()
    priceChange()
    LastData(record)
    pageData.sideTitle = '委外订单报价录入'
    pageData.showAdd = true
    pageData.isEdit = true
    pageData.pageLoading = false
  }

  const formRef = ref<FormInstance>()
  const sideOk = () => {
    formRef.value?.validate().then((err) => {
      if (!err) {
        formRef.value?.validate().then((err) => {
          if (!err) {
            pageData.pageLoading = true
            //获取前一次报价信息
            post({
              url: '/planSingle/orderQuotation/getQuotationByOrderId',
              data: {
                orderId: gridOption.value.getSelectedRows()[0].id,
              },
            })
              .then((res: any) => {
                if (res.code == 200) {
                  let ids = null
                  if (res.data != null) {
                    ids = res.data.id
                  }
                  let inStock = Object.assign(dataForm, {
                    id: ids,
                    orderId: gridOption.value.getSelectedRows()[0].id,
                  })
                  //当前报价信息
                  post({
                    url: '/planSingle/orderQuotation/quoteOrder',
                    data: inStock,
                  }).then((res: any) => {
                    if (res.code === 200) {
                      formRef.value?.resetFields()
                      for (let item in dataForm) {
                        dataForm[item] = ''
                      }
                      quoteBase64.value = ''
                      pageData.showAdd = false
                      Message.success({
                        content: '报价成功',
                        duration: 5000,
                      })
                    }
                  })
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
                doRefresh()
              })
              .finally(() => {
                pageData.pageLoading = false
              })
          }
        })
      }
    })
  }

  const sideNo = () => {
    for (let item in dataForm) {
      dataForm[item] = ''
    }
    quoteBase64.value = ''
    pageData.showAdd = false
  }

  //审核
  const auditDate = () => {
    if (gridOption1.value.getSelectedRows().length === 0) {
      Message.error('请勾选需要审核的数据')
      return
    }
    Modal.confirm({
      title: '系统提示',
      content: '是否审核此订单',
      onOk() {
        post({
          url: '/planSingle/orderQuotation/auditQuotation',
          data: {
            id: gridOption1.value.getSelectedRows()[0].id,
            auditStatus: 1,
          },
        }).then((res: any) => {
          if (res.code === 200) {
            Message.success('审核通过')
            doRefresh1()
          } else {
            Message.error(res.message)
          }
        })
      },
    })
  }

  //驳回
  const rejectData = () => {
    if (key.value == 1) {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请勾选需要驳回的数据!')
        return
      }
      Modal.confirm({
        title: '系统提示',
        content: '是否驳回此订单',
        onOk() {
          post({
            url: '/planSingle/oemOrder/updateState',
            data: gridOption.value.getSelectedRows().map((res) => res.id),
          }).then((res: any) => {
            if (res.code === 200) {
              Message.success('驳回通过')
              doRefresh()
            } else {
              Message.error(res.message)
            }
          })
        },
      })
    } else {
      if (gridOption1.value.getSelectedRows().length === 0) {
        Message.error('请勾选需要驳回的数据!')
        return
      }
      Modal.confirm({
        title: '系统提示',
        content: '是否驳回此订单',
        onOk() {
          post({
            url: '/planSingle/clothfiy/getAutomaticInfo',
            data: {
              id: gridOption1.value.getSelectedRows()[0].id,
              auditStatus: 2,
            },
          }).then((res: any) => {
            if (res.code === 200) {
              Message.success('驳回通过')
              doRefresh1()
            } else {
              Message.error(res.message)
            }
          })
        },
      })
    }
  }

  //图片上传
  const fileList: any = ref([])
  const handleChange = (fileList: any) => {
    let fileSize = fileList[0].file.size / 1024 / 1024
    if (fileSize > 5) {
      Message.error('上传图片不能超过5M')
      return
    }
    const reader = new FileReader()
    reader.readAsDataURL(fileList[0].file)
    reader.addEventListener('load', () => {
      dataForm.quotationImg = reader.result
    })
  }

  //打印
  const visible = ref(false)
  const printOk = () => {
    codes = gridOption2.value.getSelectedRows()[0].orderCode
    if (gridOption2.value.getSelectedRows().length === 0) {
      Message.error('请先勾选')
      return
    }
    post({
      url: '/planSingle/oemOrder/getOemOrderPlan',
      data: {
        id: gridOption2.value.getSelectedRows()[0].orderId,
        oemOrder: gridOption2.value.getSelectedRows()[0].orderCode,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        gridOption5.value.setRowData(res.data)
        visible.value = true
      } else {
        Message.error(res.message)
      }
    })
  }

  const bfShowAdd: any = ref(false)
  let srcUrl = ref()
  const dyBoufeixs = (record: any) => {
    post({
      url: '/planSingle/oemOrder/printVerify',
      data: {
        planOrderId: record.id,
        orderCode: gridOption2.value.getSelectedRows()[0].orderCode,
      },
    }).then((res: any) => {
      if (res.code == 200) {
        post({
          url: '/planSingle/clothfiy/getAutomaticInfo',
          data: { customName: '委外' },
        }).then((res: any) => {
          if (res.code == 200) {
            srcUrl.value = `./hiprint/Outcustom.html?modelData=${JSON.stringify(res.data)}&jhd=${
              record.planOrderCode
            }&oemCode=${codes}`
            bfShowAdd.value = true
          } else {
            Message.error(res.message)
          }
        })
      } else {
        Message.error(res.message)
      }
    })
  }

  //下拉框得到焦点
  const focusSel = () => {
    selCxAll({ settlementName: '' })
  }
  //下拉数据
  const options = ref<any>(pageData.typeList)
  const loading = ref(false)
  const handleSearch = (value: any) => {
    if (value) {
      const ob = { settlementName: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.typeList
      loading.value = false
    } else {
      options.value = []
    }
  }

  //下拉框查询
  function selCxAll(val: any) {
    post({
      url: 'purchase/SettlementType/getFieldValue',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        pageData.typeList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const yarnShow: any = ref(false)
  let obHb = {}
  let codes = ''
  //原纱出库
  const yarnOut = (record: any) => {
    codes = record.orderCode
    yarnShow.value = true
    ckSelect(record)
  }

  const ckSelect = (record: any) => {
    Len = []
    Len1 = []
    tableList3.value = []
    post({
      url: 'planSingle/oemOrder/getYarnOutInfoOem',
      data: {
        id: record.orderId,
        orderCode: record.orderCode,
      },
    }).then(({ data, code }: any) => {
      if (code == 200) {
        for (let key in data) {
          //需要合并行数 data[key].length
          for (let i = 0; i < data[key].length; i++) {
            data[key][i]['rowLen'] = data[key].length
            tableList3.value.push(data[key][i])
          }
        }
        //去重{j2023:6,j23031:9}
        obHb = {}
        tableList3.value.forEach(function (o: any) {
          if (!obHb.hasOwnProperty(o['planOrderCode'])) {
            obHb[o['planOrderCode']] = o['rowLen']
          }
        })
      }
    })
  }

  //合并单元格
  let Len = []
  const dataSpanMethod = ({ record, column }: any) => {
    let row = 0
    for (let key in obHb) {
      if (
        !Len.includes(record.planOrderCode) &&
        record.planOrderCode == key &&
        column.dataIndex === 'planOrderCode'
      ) {
        Len.push(key)
        row = obHb[key]
        break
      }
    }
    return {
      rowspan: row,
    }
  }
  let Len1 = []
  const dataSpanMethod1 = ({ record, column }: any) => {
    let row1 = 0
    for (let key in obHb) {
      if (
        !Len1.includes(record.planOrderCode) &&
        record.planOrderCode == key &&
        column.dataIndex === 'planOrderCode'
      ) {
        Len1.push(key)
        row1 = obHb[key]
        break
      }
    }
    return {
      rowspan: row1,
    }
  }
  //选择库存
  let selectedRowKeys = ref()
  const CKvisible = ref(false)
  const Loading = ref(false)
  const reList: any = ref()
  Loading.value = false
  const kcSeclect = (record: any) => {
    tableList4.value = []
    reList.value = record
    Loading.value = false
    post({
      url: 'wms/yarnStock/getPage',
      data: {
        firm_id: record.firmId,
        warehouse_id: record.warehouseId,
        custom_name: record.customName,
        yarn_code: record.rawmaterialCode,
        yarn_name: record.rawmaterialName,
        yarn_brand: record.yarnCard,
        production_batch: record.batch,
        level: record.level,
        match_color: record.matchColor,
        color_code: record.colorCode,
        color_name: record.colorName,
        page: pageData.page,
        size: pageData.size,
      },
    }).then((res: any) => {
      if (res.code === 200) {
        CKvisible.value = true
        Loading.value = false
        gridOption7.value.setRowData(res.data.list)
        pageData.total = res.data.total
      } else {
        Message.error(res.message)
      }
    })
    Loading.value = false
  }

  const handleOk = (record: any) => {
    if (gridOption7.value.getSelectedRows().length === 0) {
      Message.error('请先勾选')
      return false
    }
    gridOption7.value.getSelectedRows().forEach(function (item1) {
      reList.value.pieceCount = item1.pieceCount
      reList.value.pieceWeight = item1.pieceWeight
      reList.value.weightTotal = item1.weightTotal
      reList.value.firm = item1.firm
      reList.value.warehouse = item1.warehouse
      reList.value.warehouseId = item1.warehouseId
    })
    // 整件件数=配纱数量/整件件重  整数
    reList.value.pieceNumber = parseInt(reList.value.withYarnNum / reList.value.pieceWeight)
    // 散件散重=配纱数量-（整件件数*整件件重） 向上取两位小数
    let m = reList.value.withYarnNum - reList.value.pieceNumber * reList.value.pieceWeight
    reList.value.bulkWeight = Math.ceil(m * 100) / 100
    Loading.value = false
    CKvisible.value = false
    Loading.value = false
  }

  const handleNo = () => {
    CKvisible.value = false
  }

  const NumChange = (record: any) => {
    let num = parseInt(record.withYarnNum / record.pieceWeight)
    if (record.pieceNumber > num) {
      Message.warning(`整件/件数不能超过 ${num} !`)
      return false
    }
  }

  const yarnOk = () => {
    let list = []
    for (let i = 0; i < tableList3.value.length; i++) {
      if (
        tableList3.value[i].pieceNumber == null ||
        tableList3.value[i].pieceNumber == 0 ||
        tableList3.value[i].pieceNumber == ''
      ) {
        Message.warning('整件/件数不能为空!')
        return false
      }
      if (!tableList3.value[i].outStockNumber) {
        const ob = {
          oemOrder: codes,
          firmId: tableList3.value[i].firmId,
          firm: tableList3.value[i].firm,
          warehouse: tableList3.value[i].warehouseName,
          warehouseId: tableList3.value[i].warehouseId,
          outStockType: '委外出库',
          supplier: tableList3.value[i].supplierName,
          customOrderNo: tableList3.value[i].customOrderNo,
          customName: tableList3.value[i].customName,
          yarnCode: tableList3.value[i].rawmaterialCode,
          yarnName: tableList3.value[i].rawmaterialName,
          yarnBrand: tableList3.value[i].yarnCard,
          productionBatch: tableList3.value[i].batch,
          level: tableList3.value[i].level,
          matchColor: tableList3.value[i].matchColor,
          colorCode: tableList3.value[i].colorCode,
          colorName: tableList3.value[i].colorName,
          pieceNumber: tableList3.value[i].pieceNumber,
          pieceWeight: tableList3.value[i].pieceWeight,
          bulkNumber: tableList3.value[i].bulkNumber,
          bulkWeight: tableList3.value[i].bulkWeight,
          weightTotal: tableList3.value[i].withYarnNum,
          pieceCount: tableList3.value[i].pieceCount,
          bulkCount: tableList3.value[i].bulkCount,
          unit: tableList3.value[i].unit,
          orderType: 2,
          planOrderCode: tableList3.value[i].planOrderCode,
        }
        list.push(ob)
      }
    }
    if (list.length === 0) {
      Message.warning('当前委外单已申请过出库，请勿重复申请!')
      return false
    }
    post({
      url: '/wms/yarnOutStock/stockOutByPlanMaterial',
      data: list,
    }).then((res: any) => {
      if (res.code === 200) {
        Message.success(res.message)
        yarnShow.value = false
        doRefresh2()
      } else {
        Message.error(res.message)
      }
    })
  }

  function disablePreviousDates(current: {
    getFullYear: () => any
    getMonth: () => any
    getDate: () => any
  }) {
    const today = new Date()
    today.setHours(0, 0, 0, 0)

    // 获取当前日期的年、月、日
    const currentYear = current.getFullYear()
    const currentMonth = current.getMonth()
    const currentDay = current.getDate()

    // 获取今天日期的年、月、日
    const todayYear = today.getFullYear()
    const todayMonth = today.getMonth()
    const todayDay = today.getDate()

    // 比较当前日期与今天日期
    if (currentYear < todayYear) {
      return true // 当前日期的年份小于今天日期的年份，禁用选择
    } else if (currentYear === todayYear && currentMonth < todayMonth) {
      return true // 当前日期的年份等于今天日期的年份，但月份小于今天日期的月份，禁用选择
    } else if (currentYear === todayYear && currentMonth === todayMonth && currentDay < todayDay) {
      return true // 当前日期的年份和月份等于今天日期的年份和月份，但日期小于今天日期的日期，禁用选择
    }

    return false // 其他情况下日期可用
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('OutOrders-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('OutOrders-2', gridOption1, colState2, tc1)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }
  const { saveGridState: saveGridState03, updateGridState: updateGridState03 } =
    saveOrUpdateGridState03('OutOrders-3', gridOption2, colState3, tc2)
  const onColumnMoved3 = () => {
    saveGridState03()
  }
  const onColumnResized3 = () => {
    saveGridState03()
  }
  const onColumnVisible3 = () => {
    saveGridState03()
  }
</script>

<style scoped lang="less">
  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.arco-upload-progress) {
    display: none;
  }

  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
